package com.etc.team2.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.team2.bean.Line;
import com.etc.team2.service.LineService;

public class AllLineServlet extends HttpServlet {

	/**
	 * 用于获取所有线路的SERVLET
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		/*
		 * 调用LineService 中的getAllLine()方法，获取全部line信息，发送给lineupate.jsp
		 * 跳转到lineupdate.jsp
		 * 可参考AllStationServlet方法
		 * 在lineupdat.jsp中用EL表达式
		 */
		String referer=request.getHeader("referer");
		if (referer==null||!referer.startsWith("http://localhost:")) {
			response.sendRedirect("home.jsp");
			return;
		}
		List<Line> lines=new LineService().getAllLine();
		request.setAttribute("lines", lines);
		request.getRequestDispatcher("lineshow.jsp").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}
